home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlb20 / lib / time.c < prev    next >
C/C++ Source or Header  |  1992-05-15  |  1KB  |  52 lines

  1. /* time.c : return the elapsed seconds since midnight Jan 1 1970 GMT */
  2. /* written by Eric R. Smith and placed in the public domain */
  3.  
  4. #include <time.h>
  5. #include <osbind.h>
  6.  
  7. static struct tm this_tm;
  8. int _dst;
  9.  
  10. /* unixtime: convert a DOS time/date pair into a unix time */
  11. /* in case people were wondering about whether or not DST is applicable
  12.  * right now, we set the external variable _dst to the value
  13.  * returned from mktime
  14.  */
  15.  
  16. time_t 
  17. _unixtime(dostime, dosdate)
  18.     unsigned dostime, dosdate;
  19. {
  20.     time_t t;
  21.     struct tm *stm = &this_tm;
  22.  
  23.     stm->tm_sec = (dostime & 31) << 1;
  24.     stm->tm_min = (dostime >> 5) & 63;
  25.     stm->tm_hour = (dostime >> 11) & 31;
  26.     stm->tm_mday = dosdate & 31;
  27.     stm->tm_mon = ((dosdate >> 5) & 15) - 1;
  28.     stm->tm_year = 80 + ((dosdate >> 9) & 255);
  29.     stm->tm_isdst = -1;    /* we don't know about DST */
  30.     stm->tm_wday = stm->tm_yday = -1; /* or about these */
  31.  
  32. /* mktime expects a local time, which is what we're giving it */
  33.     t = mktime(stm);
  34.  
  35.     _dst = (stm->tm_isdst == 1) ? 1 : 0;
  36.     return t;
  37. }
  38.  
  39. time_t time(t)
  40.     time_t *t;
  41. {
  42.     unsigned dostime, dosdate;
  43.     time_t    made;
  44.  
  45.     dostime = Tgettime();
  46.     dosdate = Tgetdate();
  47.     made = _unixtime(dostime, dosdate);
  48.     if (t)
  49.         *t = made;
  50.     return made;
  51. }
  52.